package com.wang.init;

import com.wang.servlet.DemoServlet;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import java.util.Set;

/**
 * spi机制进行加载该类并实例化对象给tomcat
 */
public class DemoServletContainerInitializer implements javax.servlet.ServletContainerInitializer {

    @Override
    public void onStartup(Set<Class<?>> set, ServletContext servletContext) throws ServletException {
        System.out.println("DemoServletContainerInitializer#onStartup");

        /**
         * 使用这种方式替代web.xml中的servlet配置
         */
        //servletContext.addServlet("demoServlet",new DemoServlet()).addMapping("/abc");
    }
}
